package com.vizhuo.base.model;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AjaxResult<T> {
    private static Logger log = LoggerFactory.getLogger(AjaxResult.class);

    private boolean success = true;// 默认true

    private String msg;

    private List resultList = new ArrayList();

    private T model;

    private String errorMsg;

    public T getModel() {
        return model;
    }

    public void setModel(T model) {
        this.model = model;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List getResultList() {
        return resultList;
    }

    public void setResultList(List resultList) {
        this.resultList = resultList;
    }

    public AjaxResult(boolean success, String msg, List resultList) {
        super();
        this.success = success;
        this.msg = msg;
        this.resultList = resultList;
    }

    public AjaxResult(boolean success, String msg) {
        super();
        this.success = success;
        this.msg = msg;
    }

    public AjaxResult() {
        super();
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
        this.setSuccess(false);
        log.error(errorMsg);
    }

    public static AjaxResult setErrorMsg(AjaxResult result, String errorMsg) {
        if (result == null)
            result = new AjaxResult();
        result.errorMsg = errorMsg;
        result.setSuccess(false);
        result.log.error(errorMsg);
        return result;
    }
}
